package com.xncoding.aop.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * 目标对象target的类型是否和within中指定的类型匹配
 */
@Aspect
@Component
public class AopWithin {

    /**
     * 指定c1以及期子类
     * 所有方法
     * +号代表期子类
     */
    @Pointcut("within(com.xncoding.aop.service.within.C1+)")
    public void within00() {
    }

    /**
     * 指定c1所有方法
     */
    @Pointcut("within(com.xncoding.aop.service.within.C1)")
    public void within01() {
    }

    /**
     * 匹配指定包下所有类的方法
     */
    @Pointcut("within(com.xncoding.aop..*)")
    public void within02() {
    }

    /**
     * 匹配带有指定注解的类的方法
     */
    @Pointcut("within(@com.xncoding.aop.annotation.RedisCache *)")
    public void within03() {
    }


    @Around("within00()")
    public Object arround00(ProceedingJoinPoint pjp) throws Throwable{
        System.out.println("within00 方法环绕start.....");
        try {
            Object o =  pjp.proceed();
            System.out.println("within00 方法环绕end.....");
            return o;
        } catch (Throwable e) {
            throw e;
        }
    }

}
